﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Forms;
using ObjectDanhMuc.DB;
using ObjectDanhMuc;
using CMISLibrary.Libraries;

namespace busDanhMuc
{
    public class cls_NPC_MENUOFUSER
    {
         #region   Atributes

        private cls_NPC_MENUOFUSER_Controller obj_NPC_MENUOFUSER_Controller;
        private NPC_MENUOFUSER obj_NPC_MENUOFUSER_Info;

        #endregion

        #region   Constructor

        
        public cls_NPC_MENUOFUSER()
        {
            obj_NPC_MENUOFUSER_Info = new NPC_MENUOFUSER();
            obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
        }
        public cls_NPC_MENUOFUSER(DataSet entity)
        {
            obj_NPC_MENUOFUSER_Info = new NPC_MENUOFUSER();
            obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
        }

        #endregion

        #region Method

        public DataSet select_NPC_MENUOFUSER_by_USERID(string strSUBDIVISIONID, long longUSERID)
        {
            try
            {
                var a = obj_NPC_MENUOFUSER_Controller.select_NPC_MENUOFUSER_by_USERID(strSUBDIVISIONID, longUSERID);
                if (a == null)
                {
                    return null;
                }

                var q = from p in a
                        select new 
                        {
                            p.SUBDIVISIONID,
                            p.MENUOFUSERID,
                            p.USERID,
                            p.MENUID,
                            p.CREATEDDATE,
                            p.CREATEDBY
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_MENUOFUSER";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }

            }
            catch
            {
                return null;
            }
        }       

        public bool insert_NPC_MENUOFUSER(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_MENUOFUSER_Controller == null)
                {
                    obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
                }
                return obj_NPC_MENUOFUSER_Controller.insert_NPC_MENUOFUSER();
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }       

        public bool delete_NPC_MENUOFUSER(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_MENUOFUSER_Controller == null)
                {
                    obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
                }
                return this.obj_NPC_MENUOFUSER_Controller.delete_NPC_MENUOFUSER(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }

        public long GetNextSequence(ref string strErr)
        {
            try
            {
                long nextSeq = 0;
                if (obj_NPC_MENUOFUSER_Controller == null)
                {
                    obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
                }
                return nextSeq = obj_NPC_MENUOFUSER_Controller.GetNextSequence(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return -1;
            }

        }

        public void mapEntityToInfo(DataSet Entity)
        {
            if (this.obj_NPC_MENUOFUSER_Controller == null)
            {
                this.obj_NPC_MENUOFUSER_Controller = new cls_NPC_MENUOFUSER_Controller();
            }
            if (Entity.Tables[0].Rows[0]["MENUOFUSERID"].ToString() != string.Empty)
            {
                this.obj_NPC_MENUOFUSER_Controller.pInfor.MENUOFUSERID = Convert.ToInt64(Entity.Tables[0].Rows[0]["MENUOFUSERID"]);
            }

            this.obj_NPC_MENUOFUSER_Controller.pInfor.SUBDIVISIONID = Entity.Tables[0].Rows[0]["SUBDIVISIONID"].ToString();            

            if (Entity.Tables[0].Rows[0]["USERID"].ToString() != string.Empty)
            {
                this.obj_NPC_MENUOFUSER_Controller.pInfor.USERID = Convert.ToInt16(Entity.Tables[0].Rows[0]["USERID"]);
            }
            if (Entity.Tables[0].Rows[0]["MENUID"].ToString() != string.Empty)
            {
                this.obj_NPC_MENUOFUSER_Controller.pInfor.MENUID = Convert.ToInt16(Entity.Tables[0].Rows[0]["MENUID"]);
            }

            if (Entity.Tables[0].Rows[0]["CREATEDDATE"].ToString() != string.Empty)
            {
                this.obj_NPC_MENUOFUSER_Controller.pInfor.CREATEDDATE = Convert.ToDateTime(Entity.Tables[0].Rows[0]["CREATEDDATE"].ToString());
            }
            else
            {
                this.obj_NPC_MENUOFUSER_Controller.pInfor.CREATEDDATE = DateTime.Now.Date;
            }
           
            this.obj_NPC_MENUOFUSER_Controller.pInfor.CREATEDBY = Entity.Tables[0].Rows[0]["CREATEDBY"].ToString();

        }

        #endregion
    }
}
